import { RouterView } from 'vue-router';
import MenuPage from './pages/menu/menu';
import { defineComponent, onErrorCaptured, ref, onBeforeMount } from 'vue';
import ErrorPage from '@/components/home/error';
import './assets/css/global.less';
import { useUserInfoProvide } from '../../domain/authority/hooks/login';
import { useMenuProvide, useMenuStore } from '@/domain/dataBoard/hooks/menu';

export default defineComponent({
  name: 'App',
  setup() {
    const errorHappened = ref<boolean>(false);
    const errorMessage = ref<string>('');
    //初始化菜单
    const loginStore = useUserInfoProvide();
    useMenuProvide();
    onBeforeMount(async () => {
      await loginStore.init();
    });
    function renderNormalPage() {
      return <RouterView></RouterView>;
    }

    function renderErrorPage() {
      return <ErrorPage message={errorMessage.value} />;
    }

    return () => <>{errorHappened.value ? renderErrorPage() : renderNormalPage()}</>;
  }
});
